package com.xja.seckill.order.rabbitmq;

import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class QueueConfig {

    private static final Logger logger = LoggerFactory.getLogger(QueueConfig.class);
//创建订单交换机
    @Bean
    public DirectExchange orderExchange() {
        return new DirectExchange("order-exchange",true,false);
    }
//创建死信交换机
    @Bean
    public DirectExchange deathExchange() {
        return new DirectExchange("death-exchange",true,false);
    }
//订单队列
    @Bean
    public Queue ConsumerBeadQueue(){
        Map<String, Object> arguments  = new HashMap<> (2);
        arguments .put ("x-dead-letter-exchange","death-exchange");
        arguments .put ("x-dead-letter-routing-key","createOrder");
        return new Queue("order-queue",true,false,false,arguments);
    }
    //死信队列
    @Bean
    public Queue deathQueue() {
        return new Queue("death-queue",true);
    }

//订单队列与订单交换机绑定
    @Bean
    public Binding orderBinding() {
        return BindingBuilder.bind(ConsumerBeadQueue()).to(orderExchange ()).with ("createOrder");
    }
//死信队列与死信交换机绑定
    @Bean
    public Binding deathBinding() {
        return BindingBuilder.bind(deathQueue ()).to(deathExchange()).with("createOrder");
    }


}
